<?php

namespace App\Model;


use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class VoiceAuditConfig extends BaseModel
{
    protected $connection = 'mysql';
    protected $table = 'voice_audit_config';
    protected $primaryKey = 'id';
    protected $fillable = ['schema_name', 'interval_time', 'continue_time', 'check_items', 'check_model'];
    
    public function getIntervalTimeAttribute($intervalTime) {
        return $intervalTime ?: 0;
    }
    
    public function getContinueTimeAttribute($continueTime) {
        return $continueTime ?: 0;
    }
    
    public function getList(Request $request) {
        $limit = $request->input('limit', 10);
        $page = $request->input('page', 1);
    
        $query = new VoiceAuditConfig();
    
        // todo 搜索
    
        return $query->orderBy('id','desc')->paginate($limit, ['*'], 'page', $page);
    }
    
    public function createData($data) {
        // 检查项转为 json
        $data['check_items'] = json_encode($data['check_items']);
        return VoiceAuditConfig::create($data);
    }
    
    public function deleteData(int $id) {
        return VoiceAuditConfig::destroy([$id]);
    }
}
